package com.zhanshen.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhanshen.pojo.Company;
import com.zhanshen.pojo.Result;
import com.zhanshen.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    /**
     * 职位分页查询
     * @return
     */
    @RequestMapping("selectPagin")
    @ResponseBody
    public Result selectPagin(Company company){
        Integer start = company.getStart();
        start=start*(start-1);
        PageHelper.startPage(start,1);
        List<Company> companies = companyService.selectPagin(company);
        PageInfo<Company> pageInfo = new PageInfo<>(companies);
        List<Company> list = pageInfo.getList();
        for (Company company1 : list) {
            System.out.println(company1);
        }
        return  Result.ok(companies);
    }
    @RequestMapping("/paper")
    @ResponseBody
    public Result pageselect(Company company,Integer page){
        page=page*(page-1);
        PageHelper.startPage(page,2);
        List<Company> findall = companyService.paperselect(page);
        PageInfo<Company> pageInfo = new PageInfo<>(findall);
        List<Company> list = pageInfo.getList();
        for (Company company1 : list) {
            System.out.println(company1);
        }
        return  Result.ok();
    }
    /**
     * 职位按钮查询
     * @param company
     * @return
     */
    @RequestMapping("/buttonCompany")
    @ResponseBody
    public Result buttonCompany(Company company){
        List<Company> companies = companyService.buttonCompany(company);
        if (companies!=null){
            return Result.ok(companies);
        }
        return Result.error(666,"查询不到");
    }


}
